import Mock from "mockjs";

const usersList: any = [
  {
    username: "admin",
    password: "123456",
  },
  {
    username: "zhangsan",
    password: "abczs",
  },
];

Mock.mock("/api/users/login", "post", (options) => {
  const { username, password } = JSON.parse(options.body);

  const arr = usersList.filter((item: any) => item.username === username);
  if (arr.length === 0) {
    return {
      status: 2,
      msg: "用户不存在",
    };
  } else {
    if (arr[0].password === password) {
      return {
        status: 2,
        msg: "登录成功",
      };
    } else {
      return {
        status: 3,
        msg: "密码错误",
      };
    }
  }
});

export default Mock;
